using System;
using System.Windows.Forms;

using Tino.Core;
using Tino.Core.DBUpdates;

namespace Tino
{
    public class CheckDBValidityCommand
    {
        public CheckDBValidityCommand() { }

        public bool IsValid()
        {
            MetaInfo meta = new MetaInfo();
            int dbVersion = -1;
            try
            {
                dbVersion = meta.GetDBVersion();
            }
            catch (Exception)
            {
                MessageBox.Show("Vocable.SelectedFileInvalid", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }

            DBUpdater updater = new DBUpdater(dbVersion);
            switch (updater.GetDBStatus)
            {
                case DBStatus.TooNew:
                    MessageBox.Show("Vocable.DBUpdateTooRecent", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return false;
                case DBStatus.Outdated:
                    MessageBox.Show("Vocable.DBUpdateRequired", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return false;
            }

            return true;
        }
    }
}
